<%-- 
    Document   : enregistrerTableau
    Created on : 4 mai 2012, 13:39:18
    Author     : Morgan
--%>

<%@page import="java.util.GregorianCalendar"%>
<%@page import="java.util.Date"%>
<%@page import="Tableau.TableauFacadeLocal"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="Tableau.Tableau"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    String description = request.getParameter("description");
    Integer prixDeb = 0, annee = 0, mois = 0, jour = 0, heure = 0, minute = 0;
    int flagError = 0;
     
    if(description.isEmpty()) flagError= - 1;
        
    try
    {
        prixDeb = new Integer(request.getParameter("prixDeb"));
        annee = new Integer(request.getParameter("annee"));
        mois = new Integer(request.getParameter("mois"));
        jour = new Integer(request.getParameter("jour"));
        heure = new Integer(request.getParameter("heure"));
        minute = new Integer(request.getParameter("minutes"));
    }
    catch(Exception e){
        flagError = -1;
    }
    
    if(flagError == 0)
    {
        GregorianCalendar cal = new GregorianCalendar (annee, mois, jour, heure, minute);
        Tableau tableau = new Tableau(description, prixDeb, cal.getTime());
        InitialContext ctx = new InitialContext();
        TableauFacadeLocal tableauFacadeLocal = (TableauFacadeLocal) ctx.lookup("java:global/TP-Personne-EJB/TP-Personne-EJB-ejb/TableauFacade!Tableau.TableauFacadeLocal");
        
        tableauFacadeLocal.create(tableau);
    }
    
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link rel="stylesheet" href="styles.css" type="text/css" />
    </head>
    <body>
        <jsp:include page="menuNavigation.jsp"/>
        
        
        <div class="content">
            <h1>Insersion d'un tableau</h1>
            <% if(flagError == 0){%>

            <p>Done</p>
            <jsp:forward page="listeTableaux.jsp"/>

            <%} else{%>

            <p>Informations non valide</p>
            <a href="SaisieTableau.jsp">Retour à la saisie</a>

            <%}%>
        </div>
    </body>
</html>
